#!/bin/bash

echo 'build_path:=../../build/' > Makefile
echo 'CC:=g++' >> Makefile
include='-I../ -I../utils/ -I../main/ -I../ctrl/ -I../service/ -I../model/'
echo 'include:='${include} >> Makefile

target_prefix=$(pwd)
target_prefix=${target_prefix##*/}

declare -a sources
sources=($(ls *.cpp))
for var in ${sources[@]}; do
	object=${var/cpp/o}
	rely="${rely} "'$(build_path)'"${target_prefix}_${object}"
done

echo ${target_prefix}_.o: ${rely} >> Makefile

declare -a sources
sources=($(ls *.cpp))
for var in ${sources[@]}; do
	rely=$(g++ ${include} -MM ${var})
	rely='$(build_path)'${target_prefix}_${rely//'\'/}
	echo ${rely} >> Makefile
	object=${var/cpp/o}
	echo '	$(CC) -fPIC $(include) -o $(build_path)'${target_prefix}_${object} -c ${var} >> Makefile
	echo '	echo '${object}' >> $(build_path)'${target_prefix}.d >> Makefile
done

echo '.PHONY: clean' >> Makefile
echo 'clean:' >> Makefile
echo '	rm -f $(build_path)*.o' >> Makefile

